package com.itheima.tlias08_14.aop.cglib;

import lombok.extern.slf4j.Slf4j;
import org.springframework.cglib.proxy.MethodInterceptor;
import org.springframework.cglib.proxy.MethodProxy;

import java.lang.reflect.Method;

@Slf4j
public class Interceptor implements MethodInterceptor {

    @Override
    public Object intercept(Object obj, Method method, Object[] args, MethodProxy proxy) throws Throwable {
        long start = System.currentTimeMillis();
        Object o = proxy.invokeSuper(obj, args);
        long processTime = System.currentTimeMillis() - start;
        log.info("方法{} 执行用时 processTime = {} s",method.getName(), processTime / 1000.0);
        return o;
    }
}
